﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data;
using System.IO;

using NPOI;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using NPOI.XSSF.UserModel;

namespace DZDToExcel
{
    class DZH
    {
        private static HSSFWorkbook workbook = new HSSFWorkbook();
        MsSqlHelper mssql = new MsSqlHelper();
        Common init = new Common();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="EnterpriseName"></param>
        /// <param name="fileName"></param>
        /// <param name="Id"></param>
        public void ExportExcel(string EnterpriseName, string fileName, string Id)
        {
            try
            {
                DataTable order = DzHHZ(Id);

                DataSet orderdtl = DzHMX(Id);
                int rowNum = orderdtl.Tables[0].Rows.Count;              
                    
                    workbook.Clear();
                    NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("对账函");
                    MemoryStream ms = new MemoryStream();
                    for (int i = 2; i < 9; i++)
                    {
                        //列宽
                        sheet.SetColumnWidth(i, 13 * 256);
                    }
                    sheet.SetColumnWidth(0, 12 * 256);
                    sheet.SetColumnWidth(1, 16 * 256);

                    NRangeTitle(sheet, 0, 0, 0, 8, 18, true, EnterpriseName + "对账确认函");
                    NRangeTitle(sheet, 1, 6, 1, 1, 6, 8, 10, false, "对账函编号：" + order.Rows[0]["djbh"].ToString());
                    //NRangeTitle(sheet, rowCount + 14, 6, rowCount + 14, rowCount + 14, 6, 8, 12, false, "发函公司（盖章）");
                    NRangeTitle(sheet, 2, 0, 2, 2, 0, 8, 12, false, "甲方：" + EnterpriseName);

                    NRangeTitle(sheet, 3, 0, 3, 3, 0, 8, 12, false, "乙方：" + order.Rows[0]["danwbh"].ToString() + order.Rows[0]["dwmch"].ToString());
                    NRangeTitle(sheet, 4, 0, 4, 4, 0, 8, 10, false, "    非常感谢贵公司多年以来的支持、信任！为了正确反映双方的往来账款金额，根据我司记录与贵公司核对往来账款金额。望及时准确反馈，感谢贵公司予以支持与配合!",600);
                    NRangeTitle(sheet, 5, 0, 5, 5, 0, 8, 10, false, "    若本对账函的金额与贵公司记录相符，请贵公司在“数据无误”处签章（公章/财务章）；如有不符，请在“数据不符”处盖章，并附贵司往来账务详单。列明不符金额。",600);
                    NRangeTitle(sheet, 6, 0, 6, 6, 0, 8, 10, false, "    若款项在下述截止日期之后已经结算清讫，仍请及时回函为盼！");
                    NRangeTitle(sheet, 7, 0, 7, 7, 0, 8, 10, false, "    感谢贵公司协助！联系电话：028-83421104 回寄地址：四川省成都市金牛区金丰路112号六幢1、2、3、4层5、6号");

                    NPOI.SS.UserModel.IRow Row = sheet.CreateRow(8);
                    NRangeTitle(sheet, Row, 0, 12, false, "日期");
                    NRangeTitle(sheet, Row, 1, 12, false, "单据编号");
                    NRangeTitle(sheet, Row, 2, 12, false, "摘要");
                    NRangeTitle(sheet, Row, 3, 12, false, "采购金额");
                    NRangeTitle(sheet, Row, 4, 12, false, "付款金额");
                    NRangeTitle(sheet, Row, 5, 12, false, "销售金额");
                    NRangeTitle(sheet, Row, 6, 12, false, "回款金额");
                    NRangeTitle(sheet, Row, 7, 12, false, "余额");
                    NRangeTitle(sheet, Row, 8, 12, false, "备注");

                    NPOI.SS.UserModel.IRow TRow = sheet.CreateRow(9);
                    sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(9, 9, 0, 6));
                    NRangeTitle(sheet, TRow, 0, 10, true, "上期余额");
                    NRangeTitle(sheet, TRow, 1, 10, false, "");
                    NRangeTitle(sheet, TRow, 2, 10, false, "");
                    NRangeTitle(sheet, TRow, 3, 10, false, "");
                    NRangeTitle(sheet, TRow, 4, 10, false, "");
                    NRangeTitle(sheet, TRow, 5, 10, false, "");
                    NRangeTitle(sheet, TRow, 6, 10, false, "");
                    NRangeTitle(sheet, TRow, 7, 10, true, order.Rows[0]["shqye"].ToString());
                    NRangeTitle(sheet, TRow, 8, 10, false, "");

                    int rowCount = orderdtl.Tables[0].Rows.Count;
                    int colCount = orderdtl.Tables[0].Columns.Count;

                    for (int i = 0; i < rowCount; i++)
                    {
                        NPOI.SS.UserModel.IRow dataRow = sheet.CreateRow(i + 10);
                        NRangeTitle(sheet, dataRow, 0, 10, false, orderdtl.Tables[0].Rows[i]["ckkrq"].ToString());
                        NRangeTitle(sheet, dataRow, 1, 10, false, orderdtl.Tables[0].Rows[i]["ckdjbh"].ToString());
                        NRangeTitle(sheet, dataRow, 2, 9, false, orderdtl.Tables[0].Rows[i]["zhy"].ToString());
                        NRangeTitle(sheet, dataRow, 3, 10, false, orderdtl.Tables[0].Rows[i]["goujje"].ToString());
                        NRangeTitle(sheet, dataRow, 4, 10, false, orderdtl.Tables[0].Rows[i]["fukje"].ToString());
                        NRangeTitle(sheet, dataRow, 5, 10, false, orderdtl.Tables[0].Rows[i]["xshje"].ToString());
                        NRangeTitle(sheet, dataRow, 6, 10, false, orderdtl.Tables[0].Rows[i]["huikje"].ToString());
                        NRangeTitle(sheet, dataRow, 7, 10, false, orderdtl.Tables[0].Rows[i]["yshye"].ToString());
                        NRangeTitle(sheet, dataRow, 8, 10, false, "");
                    }


                    NPOI.SS.UserModel.IRow SumRow = sheet.CreateRow(rowCount + 10);
                    sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rowCount + 10, rowCount + 10, 0, 2));
                    NRangeTitle(sheet, SumRow, 0, 10, true, "合计");
                    NRangeTitle(sheet, SumRow, 1, 10, false, "");
                    NRangeTitle(sheet, SumRow, 2, 10, false, "");
                    NRangeTitle(sheet, SumRow, 3, 10, true, order.Rows[0]["goujje"].ToString());
                    NRangeTitle(sheet, SumRow, 4, 10, true, order.Rows[0]["fukje"].ToString());
                    NRangeTitle(sheet, SumRow, 5, 10, true, order.Rows[0]["xshje"].ToString());
                    NRangeTitle(sheet, SumRow, 6, 10, true, order.Rows[0]["huikje"].ToString());
                    NRangeTitle(sheet, SumRow, 7, 10, false, "");
                    NRangeTitle(sheet, SumRow, 8, 10, false, "");


                    NRangeTitle(sheet, rowCount + 11, 0, rowCount + 11, rowCount + 11, 0, 8, 12, true, "截止到" + order.Rows[0]["end_rq"].ToString() + "甲乙双方应收应付及付款相抵减后乙方欠甲方货款：" + order.Rows[0]["bqdzje"].ToString() + "元");
                    NRangeTitle(sheet, rowCount + 12, 0, rowCount + 12, rowCount + 12, 0, 8, 12, true, "大写人民币(负数表示应付)：" + MoneyToChinese(order.Rows[0]["bqdzje"].ToString()));
                    NRangeTitle(sheet, rowCount + 13, 0, rowCount + 13, rowCount + 13, 0, 8, 12, false, "");
                    NRangeTitle(sheet, rowCount + 14, 6, rowCount + 14, rowCount + 14, 6, 8, 12, false, "发函公司（盖章）");
                    NRangeTitle(sheet, rowCount + 15, 6, rowCount + 15, rowCount + 15, 6, 8, 12, false, "    年  月   日");
                    NRangeTitle(sheet, rowCount + 16, 0, rowCount + 16, rowCount + 16, 0, 8, 12, false, "");
                    NRangeTitle(sheet, rowCount + 17, 0, rowCount + 17, rowCount + 17, 0, 8, 12, true, "    若款项在截止日之后已经付清，仍请及时函复为盼。 ");
                    NPOI.SS.UserModel.IRow XRow = sheet.CreateRow(rowCount + 18);

                    //NRangeFoot(sheet, XRow, 1, 12, false, "1.信息证明无误。");
                    //NRangeFoot(sheet, XRow, 6, 12, false, "2.信息不符，请列明不符项目及具体内容。");
                    NRangeFoot(sheet, XRow, 1, rowCount + 18, rowCount + 18, 1, 2, 12, false, "1.信息证明无误。");
                    NRangeFoot(sheet, XRow, 5, rowCount + 18, rowCount + 18, 5, 8, 12, false, "2.信息不符，请列明不符项目及具体内容。");
                    NRangeTitle(sheet, rowCount + 19, 0, rowCount + 19, rowCount + 19, 0, 8, 12, false, "");
                    NRangeTitle(sheet, rowCount + 20, 0, rowCount + 20, rowCount + 20, 0, 8, 12, false, "");

                    NPOI.SS.UserModel.IRow FRow1 = sheet.CreateRow(rowCount + 21);
                    NRangeFoot(sheet, FRow1, 0, rowCount + 21, rowCount + 21, 0, 2, 12, false, "（被询证单位盖章）");
                    //NRangeFoot(sheet, FRow1, 1, 12, true, "（被询证单位盖章）");
                    NRangeFoot(sheet, FRow1, 1, 12, false, "");
                    NRangeFoot(sheet, FRow1, 2, 12, false, "");
                    NRangeFoot(sheet, FRow1, 4, rowCount + 21, rowCount + 21, 4, 6, 12, false, "（被询证单位盖章）");
                    //NRangeFoot(sheet, FRow1, 5, 12, true, "（被询证单位盖章）");
                    NRangeFoot(sheet, FRow1, 5, 12, false, "");
                    NRangeFoot(sheet, FRow1, 6, 12, false, "");

                    NPOI.SS.UserModel.IRow FRow2 = sheet.CreateRow(rowCount + 22);
                    NRangeFoot(sheet, FRow2, 1, 12, false, "    年  月   日");
                    NRangeFoot(sheet, FRow2, 6, 12, false, "    年  月   日");
                    NPOI.SS.UserModel.IRow FRow3 = sheet.CreateRow(rowCount + 23);
                    NRangeFoot(sheet, FRow3, 1, 12, false, "经办人:");
                    NRangeFoot(sheet, FRow3, 6, 12, false, "经办人:");


                    workbook.Write(ms);
                    FileStream file = new FileStream(fileName, FileMode.Create);
                    workbook.Write(file);
                    file.Close();
                    //workbook = null;
                    ms.Close();
                    ms.Dispose();
            }
            catch (Exception ex)
            {
                init.WriteLog(ex.ToString(), true);
                
            }

        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sheet">表格</param>
        /// <param name="startrow">起始行</param>
        /// <param name="endrow">结束行</param>
        /// <param name="startcell">起始列</param>
        /// <param name="endcell">结束列</param>
        /// <param name="fontsize">字体</param>
        /// <param name="isBold">是否加粗</param>
        /// <param name="value">内容</param>
        /// <param name="RowHeight">行高默认440=</param>
        private void NRangeTitle(NPOI.SS.UserModel.ISheet sheet, int startrow, int endrow, int startcell, int endcell, short fontsize, bool isBold, string value,short RowHeight=440)
        {

            ICellStyle style = workbook.CreateCellStyle();//创建样式对象
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //水平居中
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
            style.WrapText = true;
            NPOI.SS.UserModel.IFont font = workbook.CreateFont(); //创建一个字体样式对象
            font.FontName = "宋体"; //和excel里面的字体对应
            //font.Color = new HSSFColor.PINK().GetIndex();//颜色参考NPOI的颜色对照表(替换掉PINK())
            //font.IsItalic = true; //斜体
            font.FontHeightInPoints = fontsize;//字体大小
            if (isBold)
            {
                font.Boldweight = short.MaxValue;//字体加粗
            }

            style.SetFont(font); //将字体样式赋给样式对象
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(startrow, endrow, startcell, endcell)); //合并单元格
            NPOI.SS.UserModel.IRow Row = sheet.CreateRow(0);
            Row.Height = RowHeight;
            ICell Cell = Row.CreateCell(0);
            Cell.CellStyle = style;
            Cell.SetCellValue(value);
        }
        private void NRangeTitle(NPOI.SS.UserModel.ISheet sheet, int row, int cell, int startrow, int endrow, int startcell, int endcell, short fontsize, bool isBold, string value, short RowHeight = 440)
        {
            ICellStyle style = workbook.CreateCellStyle();//创建样式对象
            //style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //水平居中
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
            style.WrapText = true;
            NPOI.SS.UserModel.IFont font = workbook.CreateFont(); //创建一个字体样式对象
            font.FontName = "宋体"; //和excel里面的字体对应
            //font.Color = new HSSFColor.PINK().GetIndex();//颜色参考NPOI的颜色对照表(替换掉PINK())
            //font.IsItalic = true; //斜体
            font.FontHeightInPoints = fontsize;//字体大小

            if (isBold)
            {
                font.Boldweight = short.MaxValue;//字体加粗
            }

            style.SetFont(font); //将字体样式赋给样式对象
            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(startrow, endrow, startcell, endcell)); //合并单元格
            NPOI.SS.UserModel.IRow Row = sheet.CreateRow(row);
            Row.Height = RowHeight;
            ICell Cell = Row.CreateCell(cell);
            Cell.CellStyle = style;
            Cell.SetCellValue(value);
        }
        //public static ICellStyle style = null;//创建样式对象
        private static ICellStyle style = workbook.CreateCellStyle();//创建样式对象
        private static void NRangeTitle(NPOI.SS.UserModel.ISheet sheet, NPOI.SS.UserModel.IRow Row, int cell, short fontsize, bool isBold, string value, short RowHeight = 440)
        {
            //ICellStyle style = workbook.CreateCellStyle();//创建样式对象
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //水平居中
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
            style.WrapText = true;
            NPOI.SS.UserModel.IFont font = workbook.CreateFont(); //创建一个字体样式对象
            font.FontName = "宋体"; //和excel里面的字体对应
            //font.Color = new HSSFColor.PINK().GetIndex();//颜色参考NPOI的颜色对照表(替换掉PINK())
            //font.IsItalic = true; //斜体
            font.FontHeightInPoints = fontsize;//字体大小

            style.BorderTop = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderBottom = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderLeft = NPOI.SS.UserModel.BorderStyle.Thin;
            style.BorderRight = NPOI.SS.UserModel.BorderStyle.Thin;

            if (isBold)
            {
                font.Boldweight = short.MaxValue;//字体加粗
            }

            style.SetFont(font); //将字体样式赋给样式对象
            //sheet.SetColumnWidth(cell, 12 * 256);
            ICell Cell = Row.CreateCell(cell);
            Cell.SetCellValue(value);
            Cell.CellStyle = style;
            Row.Height = RowHeight;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sheet"></param>
        /// <param name="Row"></param>
        /// <param name="cell"></param>
        /// <param name="fontsize"></param>
        /// <param name="isBold"></param>
        /// <param name="value"></param>
        /// <param name="RowHeight"></param>
        private static void NRangeFoot(NPOI.SS.UserModel.ISheet sheet, NPOI.SS.UserModel.IRow Row, int cell, short fontsize, bool isBold, string value, short RowHeight = 440)
        {
            ICellStyle style = workbook.CreateCellStyle();//创建样式对象
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //水平居中
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
            style.WrapText = true;
            NPOI.SS.UserModel.IFont font = workbook.CreateFont(); //创建一个字体样式对象
            font.FontName = "宋体"; //和excel里面的字体对应
            //font.Color = new HSSFColor.PINK().GetIndex();//颜色参考NPOI的颜色对照表(替换掉PINK())
            //font.IsItalic = true; //斜体
            font.FontHeightInPoints = fontsize;//字体大小

            if (isBold)
            {
                font.Boldweight = short.MaxValue;//字体加粗
            }

            style.SetFont(font); //将字体样式赋给样式对象
            //sheet.SetColumnWidth(cell, 12 * 256);
            ICell Cell = Row.CreateCell(cell);
            Cell.SetCellValue(value);
            Cell.CellStyle = style;
            Row.Height = RowHeight;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sheet">表</param>
        /// <param name="Row">行</param>
        /// <param name="cell">列</param>
        /// <param name="startrow">起始行</param>
        /// <param name="endrow">结束行</param>
        /// <param name="startcell">起始列</param>
        /// <param name="endcell">结束列</param>
        /// <param name="fontsize">字体</param>
        /// <param name="isBold">加粗</param>
        /// <param name="value">内容</param>
        /// <param name="RowHeight">行高</param>
        private static void NRangeFoot(NPOI.SS.UserModel.ISheet sheet, NPOI.SS.UserModel.IRow Row, int cell,int startrow, int endrow, int startcell, int endcell, short fontsize, bool isBold, string value, short RowHeight = 440)
        {
            ICellStyle style = workbook.CreateCellStyle();//创建样式对象
            style.Alignment = NPOI.SS.UserModel.HorizontalAlignment.Center; //水平居中
            style.VerticalAlignment = NPOI.SS.UserModel.VerticalAlignment.Center;//垂直居中
            style.WrapText = true;
            NPOI.SS.UserModel.IFont font = workbook.CreateFont(); //创建一个字体样式对象
            font.FontName = "宋体"; //和excel里面的字体对应
            //font.Color = new HSSFColor.PINK().GetIndex();//颜色参考NPOI的颜色对照表(替换掉PINK())
            //font.IsItalic = true; //斜体
            font.FontHeightInPoints = fontsize;//字体大小

            if (isBold)
            {
                font.Boldweight = short.MaxValue;//字体加粗
            }

            style.SetFont(font); //将字体样式赋给样式对象

            sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(startrow, endrow, startcell, endcell)); //合并单元格

            //sheet.SetColumnWidth(cell, 12 * 256);
            ICell Cell = Row.CreateCell(cell);
            Cell.SetCellValue(value);
            Cell.CellStyle = style;
            Row.Height = RowHeight;
        }

        private DataSet DzHMX(string djbh)
        {
            return mssql.ExecuteDs("select rtrim(b.danwbh) as danwbh,rtrim(b.dwmch) as dwmch,b.lxr,rtrim(a.djbh) as djbh,rtrim(a.ckkrq) as ckkrq,a.ckdjbh,rtrim(a.zhy) as zhy,a.goujje,a.fukje,a.xshje,a.huikje,a.ye as yshye"
                   + " from wldzdjmx a(nolock) "
                   + " join mchk b(nolock) on a.dwbh=b.dwbh "
                   + " where a.djbh='" + djbh + "'");
        }
        private DataTable DzHHZ(string djbh)
        {
            return mssql.ExecuteDt("select a.djbh,rtrim(b.danwbh) as danwbh,rtrim(b.dwmch) as dwmch,rtrim(b.lxr) as lxr,case when isnull(a.lastdate,'')='' then min(c.ckkrq) else a.lastdate end as lastdate,a.end_rq,a.bqdzje,a.shqye,"
                    + " sum(goujje) as goujje ,sum(fukje) as fukje,sum(xshje) as xshje,sum(huikje) as huikje"
                    + " from wldzdjhz a(nolock)"
                    + " join mchk b(nolock) on a.dwbh=b.dwbh ,wldzdjmx c(nolock)"
                    + " where a.djbh=c.djbh and a.djbh='" + djbh + "'"
                    + " group by a.djbh,b.danwbh,b.dwmch,b.lxr,a.lastdate,a.end_rq,a.bqdzje,a.shqye");
        }

        private int ishz(string djbh)
        {
            int result = 0;
            result = mssql.GetMaxID("select top 1 1 from wldzdjhz where is_zx='否' and djbh='" + djbh + "'");
            return result;
        }


        /// <summary>
        /// 金额转为大写金额
        /// </summary>
        /// <param name="LowerMoney"></param>
        /// <returns></returns>
        private string MoneyToChinese(string LowerMoney)
        {
            string functionReturnValue = null;
            bool IsNegative = false; // 是否是负数
            if (LowerMoney.Trim().Substring(0, 1) == "-")
            {
                // 是负数则先转为正数
                LowerMoney = LowerMoney.Trim().Remove(0, 1);
                IsNegative = true;
            }
            string strLower = null;
            string strUpart = null;
            string strUpper = null;
            int iTemp = 0;
            // 保留两位小数 123.489→123.49　　123.4→123.4
            LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();
            if (LowerMoney.IndexOf(".") > 0)
            {
                if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2)
                {
                    LowerMoney = LowerMoney + "0";
                }
            }
            else
            {
                LowerMoney = LowerMoney + ".00";
            }
            strLower = LowerMoney;
            iTemp = 1;
            strUpper = "";
            while (iTemp <= strLower.Length)
            {
                switch (strLower.Substring(strLower.Length - iTemp, 1))
                {
                    case ".":
                        strUpart = "圆";
                        break;
                    case "0":
                        strUpart = "零";
                        break;
                    case "1":
                        strUpart = "壹";
                        break;
                    case "2":
                        strUpart = "贰";
                        break;
                    case "3":
                        strUpart = "叁";
                        break;
                    case "4":
                        strUpart = "肆";
                        break;
                    case "5":
                        strUpart = "伍";
                        break;
                    case "6":
                        strUpart = "陆";
                        break;
                    case "7":
                        strUpart = "柒";
                        break;
                    case "8":
                        strUpart = "捌";
                        break;
                    case "9":
                        strUpart = "玖";
                        break;
                }

                switch (iTemp)
                {
                    case 1:
                        strUpart = strUpart + "分";
                        break;
                    case 2:
                        strUpart = strUpart + "角";
                        break;
                    case 3:
                        strUpart = strUpart + "";
                        break;
                    case 4:
                        strUpart = strUpart + "";
                        break;
                    case 5:
                        strUpart = strUpart + "拾";
                        break;
                    case 6:
                        strUpart = strUpart + "佰";
                        break;
                    case 7:
                        strUpart = strUpart + "仟";
                        break;
                    case 8:
                        strUpart = strUpart + "万";
                        break;
                    case 9:
                        strUpart = strUpart + "拾";
                        break;
                    case 10:
                        strUpart = strUpart + "佰";
                        break;
                    case 11:
                        strUpart = strUpart + "仟";
                        break;
                    case 12:
                        strUpart = strUpart + "亿";
                        break;
                    case 13:
                        strUpart = strUpart + "拾";
                        break;
                    case 14:
                        strUpart = strUpart + "佰";
                        break;
                    case 15:
                        strUpart = strUpart + "仟";
                        break;
                    case 16:
                        strUpart = strUpart + "万";
                        break;
                    default:
                        strUpart = strUpart + "";
                        break;
                }

                strUpper = strUpart + strUpper;
                iTemp = iTemp + 1;
            }

            strUpper = strUpper.Replace("零拾", "零");
            strUpper = strUpper.Replace("零佰", "零");
            strUpper = strUpper.Replace("零仟", "零");
            strUpper = strUpper.Replace("零零零", "零");
            strUpper = strUpper.Replace("零零", "零");
            strUpper = strUpper.Replace("零角零分", "整");
            strUpper = strUpper.Replace("零分", "整");
            strUpper = strUpper.Replace("零角", "零");
            strUpper = strUpper.Replace("零亿零万零圆", "亿圆");
            strUpper = strUpper.Replace("亿零万零圆", "亿圆");
            strUpper = strUpper.Replace("零亿零万", "亿");
            strUpper = strUpper.Replace("零万零圆", "万圆");
            strUpper = strUpper.Replace("零亿", "亿");
            strUpper = strUpper.Replace("零万", "万");
            strUpper = strUpper.Replace("零圆", "圆");
            strUpper = strUpper.Replace("零零", "零");

            // 对壹圆以下的金额的处理
            if (strUpper.Substring(0, 1) == "圆")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "零")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "角")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "分")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "整")
            {
                strUpper = "零圆整";
            }
            functionReturnValue = strUpper;

            if (IsNegative == true)
            {
                return "负" + functionReturnValue;
            }
            else
            {
                return functionReturnValue;
            }
        }
    }
}
